var userbooksManager;

$(function() {
	var validData = [{ valid: 1, text: '是' }, { valid: 0, text: '否'}];
	var isBackData = [{ isBack: 1, text: '是' }, { isBack: 0, text: '否'}];
	var isContinueData = [{ isContinue: 1, text: '是' }, { isContinue: 0, text: '否'}];
	
	var caseData = [];
	var classfyData = [];
	for(var i in caseList){
		var inerJson = {};
		inerJson.caseid = caseList[i].id;
		inerJson.text = caseList[i].name;
		caseData.push(inerJson);
	}
	for(var i in classfyList){
		var inerJson = {};
		inerJson.classfyid = classfyList[i].id;
		inerJson.text = classfyList[i].name;
		classfyData.push(inerJson);
	}
	userbooksManager = window['g'] = $("#maingrid").ligerGrid({
		height : '100%',
		url:'/v1/ub/getBorrows?isBack=0',
		pageSize : 10,
		columns : [ {
			display : '分类',
			name : 'classfyid',
			minWidth : 50,
			align : "center",
            render: function (item)
            {
                 for(var i in classfyData){
                	 if(item.classfyid == classfyData[i].classfyid){
                		 return classfyData[i].text;
                	 }
                 }
            },
			isSort : false
		} ,{
			display : '语言',
			name : 'language',
			minWidth : 20,
			align : "center",
			isSort : false
		}, {
			display : '书名',
			name : 'bookname',
			minWidth : 50,
			align : "center",
			minWidth : 50,
		}, {
			display : '书架',
			name : 'caseid',
			minWidth : 100,
			align : "center",
            render: function (item)
            {
                 for(var i in caseData){
                	 if(item.caseid == caseData[i].caseid){
                		 return caseData[i].text;
                	 }
                 }
            },
			isSort : false
		}, {
			display : '借出时间',
			name : 'borrowTime',
			minWidth : 100,
			align : "center",
			format : 'yyyy年MM月dd日',
			isSort : false,
			render : function(record, rowindex, value, column){
				var newDate = new Date(value);
				return newDate.format("yyyy年MM月dd日");
			}
		}, {
			display : '应还时间',
			name : 'planTime',
			minWidth : 60,
			align : "center",
			format : 'yyyy年MM月dd日',
			isSort : false,
			render : function(record, rowindex, value, column){
				var newDate = new Date(value);
				return newDate.format("yyyy年MM月dd日");
			}
		},{
			display : '是否已续借',
			name : 'isContinue',
			minWidth : 60,
			align : "center",
			isSort : false,
			render: function (item)
            {
                 if(item.isContinue == 1){
                	 return "是";
                 }else{
                	 return "否";
                 }
            },
		},{
			display : '续借操作',
			minWidth : 60,
			align : "center",
			isSort : false,
			showTitle:false,
			render: function(rowdata, rowindex)
            {
                 if(rowdata.isContinue == 1){
                	 return "已续借";
                 }else{
                	 return " <a  href='javascript:continueBorrows("+rowdata.id+");'>点击续借</a>";
                 }
            },
		}],
		rownumbers : true,
		onSelectRow: function (rowdata, rowindex)
        {
           
        },
        enabledEdit: true, 
        isScroll: false, 
        rownumbers:true
	});
	
    
    jQuery("#pageloading").hide();

});


function continueBorrows(bookId){
	jQuery.ajax({
		url:'/v1/ub/continueBorrows/'+bookId,
		dataType:'text',
		type:'post',
		success:function(data){
			userbooksManager.loadServerData({pagesize:10});
			$.ligerDialog.success(data);
		},
		error:function(){
			$.ligerDialog.error("网络错误,请稍后再试!");
		}
	});
}